package ext;

import java.util.*;
import org.junit.*;

public class Pdd2 {

    public  List<String> arrage(List<List< Integer>> nums) {

        Queue<String> queue = new LinkedList<>();
        queue.offer("");
        for (int i = 0; i < nums.size(); i++) {
            int n = queue.size();   
            for (int j = 0; j < n; j++) {
                String s = queue.poll();
                List<Integer> cur = nums.get(i);
                for (int k = 0; k < cur.size(); k++) {
                    queue.offer(s + cur.get(k));
                }
            }
        }
        return new ArrayList<>(new HashSet<>(queue));
    }

    @Test
    public void test() {
        List<List<Integer>> nums = new ArrayList<>();
        nums.add(List.of(1,2,3));
        // nums.add(List.of(4,5,6));
        nums.add(List.of(1,1,3));
        nums.add(List.of(7,8,9));

        System.out.println(arrage(nums));
    }
}
